define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'outsideschool/index' + location.search,
                    // add_url: 'outsidestudent/add',
                    // edit_url: 'outsidestudent/edit',
                    // del_url: 'outsidestudent/del',
                    multi_url: 'outsideschool/multi',
                    table: 'outsideschool',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('序号'),operate:false},
                        {field: 'applier_name', title: __('申请人名称'),operate:'LIKE'},
                        {field: 'nickname', title: __('校外人员姓名'),operate:'LIKE'},
                        {field: 'zy', title: __('专业'),operate:'LIKE'},
                        {field: 'bj', title: __('班级'),operate:'LIKE'},
                        {field: 'tel', title: __('Tel'),operate:'LIKE'},
                        {field: 'card_id', title: __('身份证号'),operate:'LIKE'},
                        {field: 'work_unit',title: __('工作单位'),operate:'LIKE'},

                        {field: 'memo',title: __('访问事由'),operate:'LIKE'},
                        {field: 'car_number',title: __('车牌号'),operate:'LIKE'},



                        {field: 'admission_starttime',title: __('入校开始时间'),operate: false},
                        {field: 'admission_endtime',title: __('入校截止时间'),operate: false},
                        {field: 'reception_name',title: __('接待单位'),operate:'LIKE'},
                        {field: 'is_check',title: __('审核状态'),operate:false,
                            formatter: function (value,row,index) {
                                if(value == 1) {
                                    return '<a href="javascript:;" class="btn btn-xs btn-success">已审核</a>';
                                }else if(value == 2){
                                    return '<a href="javascript:;" class="btn btn-xs btn-danger">已驳回</a>';
                                }else{
                                    return '<a class="btn btn-primary btn-xs">待审核</a>';
                                }

                            },
                            searchList: {"0": __('待审核'), "1": __('已审核'), "2": __('已驳回')}
                        },
                        {field: 'gate_name',title: __('进入的校门'),operate:'LIKE'},
                        {field: 'check_cn',title: __('审核人'),operate:'LIKE'},
                        // {field: 'gate_name',title: __('审核时间'),operate:'LIKE'},
                        {field: 'check_time', title: __('审核时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            $(".btn-export").click(function () {
                var parenttable = table.closest('.bootstrap-table');
                var options = table.bootstrapTable('getOptions');
                var toolbar = $(options.toolbar, parenttable);
                var search = options.queryParams({});
                var filter = JSON.parse(search.filter);
                var op = JSON.parse(search.op);
                url = 'outsideschool/export';
                Backend.api.addtabs(url, '', '');
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});